package com.qf.day12.linkedList;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class TextEditorServiceImpl implements TextEditorService{
    List<String> list =  new LinkedList<>();
    private int count = 0;
    @Override
    public boolean addLine(String line) {
        list.add(line);
        count++;
        return true;
    }

    @Override
    public List<String> getALl() {

        return list;
    }

    @Override
    public boolean updateLine(int lineNum, String line) {
        if(lineNum>=count){
            return false;
        }
        list.set(lineNum-1,line);
        return true;
    }

    @Override
    public boolean deleteLine(int lineNum) {
        if(lineNum>=count || lineNum==0){
            return false;
        }
        list.remove(lineNum-1);
        count--;
        return true;
    }

    @Override
    public boolean insertLine(int lineNum, String line) {
        if(lineNum>=count){
            return false;
        }
        list.add(lineNum-1,line);
        count++;
        return true;
    }
}
